import numpy as np

import constants as c


class TASK:
    
    
    def __init__(self) -> None:
        
        self.network = self.__create_network()
        
            
    def __create_network(self):
        
        np.random.seed()
        return np.random.random((c.link_sensor_num, c.motor_num)) * 2 - 1
    
    
    def load_network(self, network):
        
        if network is not None:
            self.network = np.load(network)
            
            
    def act(self, link_sensor_value):
        
        return np.matmul(link_sensor_value, self.network)
    
    
    def mutate(self):
        
        """产生变异"""

        x = np.random.randint(0, c.link_sensor_num - 1)
        y = np.random.randint(0, c.motor_num - 1)
        self.network[x][y] = np.random.random() * 2 - 1
        
